package com.cindata

import com.cindata.dictionary.*

class Contact
{

    ContactImportBatch batch

    ContactType type
    //     类型
    String fullName
    //    主借款人姓名
    String cellphone
    //    主借款人联系电话

    String phoneOperator
    // 运营商品牌
    Province phoneBelongProvince
    // 手机号码归属省份
    City phoneBelongCity
    // 手机号码归属城市
    Integer phoneOnLineDuration
    // 在网时长(月) 
    Date phoneStartTime
    // 开卡时间
    Date phoneEndTime
    // 销号时间 
    String phoneOnLineStatus
    // 在网状态
    Boolean phoneIsInUse = true
    // 是否使用

    String sex
    // 性别
    String degree
    // 学历
    String householdAddress
    // 户口所在地
    String householdType
    // 户口性质
    String maritalStatus = "未婚"
    // 婚姻状态
    String title
    // 职称
    String position
    // 职务
    ContactIdentityType identityType
    //    身份证件类型
    String idNumber
    //    主借款人身份证号
    Date birthday
    //    主借款人出身年月日
    AccountNatureDict accountNature
    //    主借款人户口类型
    Integer ownHouseCount
    //    主借款人家庭已购房套数
    String workUnitName
    //    主借款人工作单位名称
    OrganizationNatureDict workUnitNature
    //    主借款人工作单位性质
    DepositedStateDict depositedState
    //    主借款人当前缴存状态
    BigDecimal depositBaseOnLoans
    //    主借款人贷款时月缴存基数（元）
    BigDecimal depositAmountOnLoans
    //    主借款人贷款时月缴存额（元）
    BigDecimal depositBaseOnCurrent
    //    主借款人当前月缴存基数（元）
    BigDecimal depositAmountOnCurrent
    //    主借款人当前月缴存额（元）
    BigDecimal fmiOnLoans
    //    主借款人贷款时家庭月收入（元）
    String address
    //    主借款人地址
    String publicFundAccount
    //    主借款人公积金账号

    String debitCardNumber
    // 借记卡卡号

    String creditLevel
    // 信用等级(机构内部评定)
    BigDecimal creditAmount
    // 信用额度
    BigDecimal creditBalance
    // 信用余额

    Double creditScore
    // 信用评分（借款人风险预警）
    String creditRiskLevel
    // 信用等级（风险预警）
    String latestCreditRiskLevel
    // 最新信用等级（风险预警）
    Date creditLatestQueryDate
    // 信用最新查询日期（风险预警）
    
    Double sharePoint
    // 房产共有人所占份额

    BigDecimal monthlyIncome
    // 借款人月收入金额

    RiskWarningStatusDict warningStatus
    RiskWarningDealTypeDict dealType

    Date createdDate = new Date()
    Date modifiedDate = new Date()
    User user
    User createBy
    User modifyBy

    static belongsTo = [account: Account]

    static mapping = {
        autowire true
    }

    static constraints = {
        batch nullable: true, blank: true, comment: '批次号'

        type nullable: true, blank: true, comment: '类型'
        fullName maxSize: 50, nullable: true, blank: true, comment: '姓名'
        cellphone maxSize: 20, nullable: true, blank: true, comment: '联系电话'
        cellphone unique: true

        phoneOperator maxSize: 50, nullable: true, blank: true, comment: '手机号运营商'
        phoneBelongProvince nullable: true, blank: true, comment: '所属省份'
        phoneBelongCity nullable: true, blank: true, comment: '所属城市'
        phoneOnLineDuration nullable: true, blank: true, comment: '在网时长'
        phoneStartTime nullable: true, blank: true, comment: '开卡时间'
        phoneEndTime nullable: true, blank: true, comment: '注销时间'
        phoneOnLineStatus maxSize: 30, nullable: true, blank: true, comment: '在网状态'
        phoneIsInUse nullable: true, blank: true, comment: '是否使用'

        identityType blank: true, nullable: true, comment: '证件类型'
        idNumber maxSize: 18, nullable: true, blank: true, comment: '证件号'
        birthday nullable: true, blank: true, comment: '出身年月日'
        accountNature nullable: true, blank: true, comment: '主借款人户口性质'
        ownHouseCount maxSize: 8, nullable: true, blank: true, comment: '家庭已购房套数'
        workUnitName maxSize: 100, nullable: true, blank: true, comment: '工作单位名称'
        workUnitNature nullable: true, blank: true, comment: '工作单位性质'
        depositedState nullable: true, blank: true, comment: '当前缴存状态'
        depositBaseOnLoans nullable: true, blank: true, precision: 15, scale: 2, comment: '贷款时月缴存基数（元）'
        depositAmountOnLoans nullable: true, blank: true, precision: 15, scale: 2, comment: '贷款时月缴存额（元）'
        depositBaseOnCurrent nullable: true, blank: true, precision: 15, scale: 2, comment: '当前月缴存基数（元）'
        depositAmountOnCurrent nullable: true, blank: true, precision: 15, scale: 2, comment: '当前月缴存额（元）'
        fmiOnLoans nullable: true, blank: true, precision: 15, scale: 2, comment: '贷款时家庭月收入（元）'
        address maxSize: 150, nullable: true, blank: true, comment: '地址'
        publicFundAccount maxSize: 50, nullable: true, blank: true, comment: '公积金账号'

        creditLevel maxSize: 50, nullable: true, blank: true, comment: '信用等级'
        creditAmount nullable: true, blank: true, comment: '信用额度'
        creditBalance nullable: true, blank: true, comment: '信用余额'

        account blank: true, nullable: true, comment: '所属机构（担保机构）'

        sex maxSize: 2, blank: true, nullable: true
        sex inList: ["男", "女"]
        degree maxSize: 20, blank: true, nullable: true
        degree inList: ["小学", "初中", "高中", "大专", "本科", "硕士研究生", "博士研究生", "其他"]
        householdAddress maxSize: 150, blank: true, nullable: true
        householdType maxSize: 10, blank: true, nullable: true
        householdType inList: ["农业户口", "非农业户口"]
        maritalStatus maxSize: 10, blank: true, nullable: true
        maritalStatus inList: ["未婚", "已婚", "再婚", "离异", "丧偶"]
        title maxSize: 50, blank: true, nullable: true
        position maxSize: 50, blank: true, nullable: true

        sharePoint blank: true, nullable: true

        createdDate nullable: true, blank: true
        modifiedDate nullable: true, blank: true
        user nullable: true, blank: true
        createBy nullable: true, blank: true
        modifyBy nullable: true, blank: true

        creditScore nullable: true, blank: true
        creditRiskLevel maxSize: 50, nullable: true, blank: true
        latestCreditRiskLevel maxSize: 50, nullable: true, blank: true
        creditLatestQueryDate nullable: true, blank: true
        
        debitCardNumber maxSize: 50, nullable: true, blank: true

        warningStatus nullable: true, blank: true
        dealType nullable: true, blank: true
        
        monthlyIncome nullable: true, blank: true
    }

    def springSecurityService
    def beforeInsert()
    {
        def username = springSecurityService?.getPrincipal()?.username
        def user = User.findByUsername(username)
        createBy = user
        account = user?.account
    }

    def beforeUpdate()
    {
        modifiedDate = new Date()
        def username = springSecurityService?.getPrincipal()?.username
        modifyBy = User.findByUsername(username)
    }
}
